package config

import (
	"flag"

	"github.com/BurntSushi/toml"
)

type config struct {
	AppName   string
	Url       string
	Port      string
	Database  map[string]database
	Wechat    map[string]wechat
	Wechatpay map[string]wechatpay
	Alipay    alipay
	Redis     redis
	Aliyun    aliyun
}

type redis struct {
	Addr     string
	Password string
}

type database struct {
	DSN    []string
	Active int
	Idle   int
}

type wechat struct {
	Appid     string
	Appsecret string
}

type wechatpay struct {
	Mchid  string
	Mchkey string
}

type alipay struct {
	Appid  string
	Secret string
}

type aliyun struct {
	AliyunEndPoint        string
	AliyunBucket          string
	AliyunBucketDomin     string
	AliyunBucketStyle     string
	AliyunAccessKeyID     string
	AliyunAccessKeySecret string
}

// Config global config
var Config config

var (
	tomlFile = flag.String("config", "app.toml", "config file")
)

// Init load config
func Init() {
	Config = config{}
	_, err := toml.DecodeFile(*tomlFile, &Config)
	if err != nil {
		panic(err)
	}
}
